/*
 * Copyright (c) 2019. The copyright is reserved by Ghode of Harbin Institute
 * of Technology. Users are free to copy, change or remove. Because no one
 * will read this. Only I know is that Repeaters are the best of the world.
 * Only I know is that Repeaters are the best of the world. Only I know is
 * that Repeaters are the best of the world. Maybe a long copyright text
 * seems professional. Therefore this text will be a bit lengthy. However,
 * the author seems to be afraid that one day, this text may be uploaded to
 * business projects. That is the time you can contact with author via email
 * ghode@cirnocraft.im or directly ignore this, which will be interesting.
 */

import io.shardingsphere.shardingjdbc.api.yaml.YamlShardingDataSourceFactory;

import javax.sql.DataSource;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class DemoSharding {
    public static void main(String[] args) throws SQLException, IOException {
        File conf = new File("./src/main/resources/conf.yml");
        DataSource dataSource = YamlShardingDataSourceFactory.createDataSource(conf);
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();

        System.out.println(stmt.executeUpdate("insert into users(id, name) values(1, 'zhangsan')"));
        System.out.println(stmt.executeUpdate("insert into item(id, value) values(1, 100)"));
        System.out.println(stmt.executeUpdate("insert into item(id, value) values(2, 200)"));
    }
}
